package cn.org.service.test;

import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.Transactional;

import cn.org.domain.Org;
import cn.org.domain.Person;
import cn.org.dto.TreeDto;
import cn.org.service.IOrgService;
import cn.org.service.IPersonService;

@ContextConfiguration(locations={"classpath:spring-mybatis.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
@Transactional
//如果是true不会改变数据库数据，如果是false会改变数据
@TransactionConfiguration(transactionManager="transactionManager",defaultRollback=true)
public class testPersonService {
	
	@Autowired
    private IPersonService personService;
	
	@Autowired
    private IOrgService orgService;

	@Before
	public void setUp() {
		
	}
	
	@After
	public void tearDown() {
		
	}
	@Test
	public void testInsertperson(){
		Person person=new Person();
		person.setName("李四");
		person.setPhone("123456");
		person.setSex(1);
		person.setSn("zfbm");
		personService.insert(person);
		
	}
	@Test
	public void testGetAllperson(){
		List<Person> list=personService.getALLPerson();
		for(Person p:list){
			System.out.println(p);
		}
		
	}
	
	@Test
	public void testGetpersonsByOrg(){
		Org org =new Org();
		org.setId(3);
		List<Person> list=personService.getPersonsByOrg(org);
		for(Person p:list){
			System.out.println(p);
		}
		
	}
	
	@Test
	public void testGetChildOrg(){
		Org org =new Org();
		org.setId(9);
		List<Org> list=orgService.getAllChildOrg(org);
		for(Org o:list){
			System.out.println(o);
		}
		
	}
	
	@Test
	public void testlistChildTreeByOrg(){
		Org org =new Org();
		org.setId(3);
		List<TreeDto> list=orgService.listChildTreeByOrg(org);
		for(TreeDto o:list){
			System.out.println(o);
		}
		List<Integer> list1=orgService.listChildIdsByOrg(3);
		System.out.println(list1.size());
		for(int i:list1){
			System.out.println(i);
		}
	}
}
